<template>
  <view class="search-navbar" :style="{ paddingTop: statusBarHeight + 'px' }">
    <tn-navbar
        backgroundColor="#ffffff"
        :border="false"
        :height="navHeight"
        :bottom-shadow="false"
        :top-shadow="false"
        :customBack="false"
    >
      <!-- 左侧图标 -->
      <template #back style="line-height: 36px">
        <image
            v-if="!isBack && showIcon"
            src="https://cdn.nlark.com/yuque/0/2023/png/280373/1679989824360-assets/web-upload/d6f05bc7-7e47-4566-98fc-494350f4f5d2.png"
            class="nav-icon"
            style="width: 30px; height: 30px"
        />
        <view v-if="isBack" @click="back" style="width: 100%; height: 100%">
          <TnIcon   name="left" size="20px" style="top: 12px"></TnIcon>
        </view>

      </template>
      <TnSearchBox
          v-if="props.isSearch"
          style="background: #f5f5f5; border-radius: 20px; height: 30px; display: flex; align-items: center; padding: 0 10px; width: 150px; margin-left: -100px"
          shape="round"
          :search-button="false"
          :border="false"
      />
      <span v-else class="title-text">{{ title }}</span>
    </tn-navbar>
    <view>
      <slot name="other"></slot>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import TnNavbar from '@tuniao/tnui-vue3-uniapp/components/navbar/src/navbar.vue'
import TnSearchBox from '@tuniao/tnui-vue3-uniapp/components/search-box/src/search-box.vue'
import TnIcon from '@tuniao/tnui-vue3-uniapp/components/icon/src/icon.vue'
const props = defineProps({
  placeholder: { type: String, default: '搜索订单号' },
  navHeight: { type: String, default: '44px' },
  isSearch: { type: Boolean, default: true },
  title: { type: String, default: '' },
  isBack: { type: Boolean, default: false },
  showIcon: { type: Boolean, default: false },
})

const statusBarHeight = ref(0)

onMounted(() => {
  const sysInfo = uni.getSystemInfoSync()
  statusBarHeight.value = sysInfo.statusBarHeight || 20;
})

const back = () => {
  if(props.isBack) {
    uni.navigateBack();
  }
}

function onSearch(e) {
  console.log('搜索内容：', e.detail.value)
}
const setHeight = (isSearch: boolean = true) => {
  if (isSearch) {
    statusBarHeight.value = 0;
  } else {
    const sysInfo = uni.getSystemInfoSync()
    statusBarHeight.value = sysInfo.statusBarHeight || 20
  }

}
defineExpose({
  setHeight
})
</script>

<style scoped lang="scss">
.search-navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  background: #ffffff;
}

.nav-icon {
  width: 32rpx;
  height: 32rpx;
  border-radius: 50%;
  animation: rotate 5s linear infinite;
}
@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.search-box {
  flex: 1;
  height: 30px;
}

.search-input {
  flex: 1;
  font-size: 14px;
  border: none;
  background: transparent;
}
:deep(.tn-navbar__content) {
  padding-left: 0;
}
.title-text {
  color: #333333;
  font-size: 16px;
}

</style>
<style>
.tn-shadow {
  box-shadow: 0 0 rgba(255, 255, 255, 1) !important;
}
</style>
